/**
 * Author: 罗建武
 * Remark: 选择商品公共组件
 * createTime: 2020-07-02
 */
lyfdefine(function () {
    return ({
        data: function () {
            return {
                dataForm: {},
                goods: [],
                dataStatusArr: {
                    "0": "处理中",
                    "1": "成功",
                    "2": "失败"
                },
                dataTypeArr: {
                   1: "导出",
                   2: "导入"
                },
                pageIndex: 1,
                pageSize: 10,
                dataList: [],
                totalPage: 0,
                types : 0,
                dataListLoading: false
            }
        },
        mounted() {

        },
        methods: {
            //根据类型获取日志信息( 1.直营预测计划2. 需求计划 3.销售计划 4.其他渠道计划)
            getDataList(type) {
                this.dataListLoading = true;
                this.dataForm.pageSize = this.pageSize;
                this.dataForm.pageNum = this.pageIndex;
                if (type) {
                    this.types = type;
                }
                this.dataForm.opSource = this.types;
                if (this.dataForm.dateRange) {
                    this.dataForm.startTime = this.dataForm.dateRange[0]
                    this.dataForm.endTime = this.dataForm.dateRange[1]
                }
                this.$http({
                    url: "/scm-plan-admin/api/v1/operationLogRecord/getOperationLogs",
                    method: 'post',
                    data: this.dataForm
                }).then(result => {
                    var data = result.data;
                    if (data && data.code === '0') {
                        this.dataList = data.data.list;
                        this.totalPage = data.data.total
                    } else {
                        this.dataList = [];
                        this.totalPage = 0
                    }
                    this.dataListLoading = false
                }).catch(reason => {
                    /*如果出现了异常，页面停止旋转*/
                    this.dataListLoading = false;
                    /*弹出提示框*/
                    this.$message.error("加载失败");
                })
            },
            // 返回
            closeChooseGoodsDialog() {
                this.$emit('closeChooseGoodsDialog')
            },
            // 每页数
            sizeChangeHandle(val) {
                this.pageSize = val;
                this.pageIndex = 1;
                this.getDataList(this.types)
            },
            // 当前页
            currentChangeHandle(val) {
                this.pageIndex = val;
                this.getDataList(this.types)
            },
            handleSelection(row, index) {
                if (row.opStatus === 1)
                    return true
                else
                    return false
            },
            reset() {
                for (key in this.dataForm) {
                    this.dataForm[key] = '';
                }
            },
            // 下载
            downLoad(filePath){
                window.location.href ='/scm-plan-admin/api/v1/operationLogRecord/downLoad?ext=' +filePath;
            }
        },
        template: `
        <div v-loading="dataListLoading">
        <div class="mod-config">
<!--    <el-card class="box-card search-input" shadow="never">-->
<!--    <el-form label-width="100px" ref="dataForm" :model="dataForm" :inline="true" size="mini" @keyup.enter.native="getDataList()">-->
<!--        <el-row>-->
<!--                <el-form-item label="状态">-->
<!--                    <el-select v-model="dataForm.opStatus"-->
<!--                        clearable-->
<!--                        filterable-->
<!--                        placeholder="选择状态">-->
<!--                        <el-option-->
<!--                            v-for="(value,key) in dataStatusArr"-->
<!--                            :key="key"-->
<!--                            :label="value"-->
<!--                            :value="key">-->
<!--                        </el-option>-->
<!--                    </el-select>-->
<!--                </el-form-item>-->
<!--                <el-form-item label="操作人">-->
<!--                    <el-input v-model="dataForm.creator" placeholder="请输入内容"></el-input>-->
<!--                </el-form-item>-->
<!--                <el-form-item label="时间段">-->
<!--                    <el-date-picker-->
<!--                    value-format="yyyy-MM-dd HH:mm:ss"-->
<!--      v-model="dataForm.dateRange"-->
<!--      type="datetimerange"-->
<!--      range-separator="至"-->
<!--      start-placeholder="开始日期"-->
<!--      end-placeholder="结束日期">-->
<!--    </el-date-picker>-->
<!--                </el-form-item>-->
<!--        </el-row>-->
<!--               <el-row>-->
<!--            <el-col :span="3" style="float: right">-->
<!--                    <el-button type="primary" size="mini" @click="getDataList()" >查询</el-button>-->
<!--                    <el-button type="primary" size="mini" @click="reset()">重置</el-button>-->
<!--                       </el-col>-->
<!--                   -->
<!--        </el-row>-->
<!--    </el-form>-->
<!--    </el-card>-->
<!--    数据列表-->
    <el-card class="box-card"> 
        <el-table :data="dataList" :header-cell-style="{'text-align':'center'}" v-loading="dataListLoading" highlight-current-row="true" size="mini" border="true"
    style="width: 100%">
            <el-table-column prop="id" label="任务编号" width="100"></el-table-column>
            <el-table-column prop="opContent" label="任务详情"></el-table-column>
            <el-table-column prop="opType" label="任务类型" width="100">
                <template slot-scope="scope">
                    <span>{{dataTypeArr[scope.row.opType]}}</span>
                </template>
            </el-table-column>
            <el-table-column prop="opStatus" label="处理状态" width="120">
                <template slot-scope="scope">
                    <span>{{dataStatusArr[scope.row.opStatus]}}</span>
                </template>
            </el-table-column>
            <!--<el-table-column prop="opTime" label="耗时" width="120">
                <template slot-scope="scope">
                    <span>{{scope.row.opTime == '0ms' ? '-' : scope.row.opTime}}</span>
                </template>
            </el-table-column>-->
              <el-table-column prop="createTime" label="任务开始时间" width="200"></el-table-column>
              <el-table-column prop="opEndTime" label="任务结束时间" width="200"></el-table-column>
            <!--<el-table-column prop="creatorName" label="处理人" width="120"></el-table-column>-->
             <el-table-column prop="failReason" width="200" label="备注"></el-table-column>
             <el-table-column header-align="center" align="center" width="100" label="操作">
        <template slot-scope="scope">
            <el-button type="primary" size="small" @click="downLoad(scope.row.ext)"  v-if = "scope.row.opType == 1 && scope.row.opStatus == 1">下载</el-button>
        </template>
    </el-table-column>
        </el-table>
        <el-pagination
                @size-change="sizeChangeHandle"
                @current-change="currentChangeHandle"
                style="float: right"
                :current-page="pageIndex"
                :page-sizes="[10, 20, 50, 100]"
                :page-size="pageSize"
                :total="totalPage"
                layout="total, sizes, prev, pager, next, jumper">
        </el-pagination>
    </el-card>
</div>
        
        
</div>
        `
    })
})
